package com.ssi.mrms.dao.mapping;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.core.RowMapper;

import com.ssi.mrms.model.Role;

public class RoleMapping implements RowMapper<Role> {

	public Role mapRow(ResultSet rs, int line) throws SQLException {
		ResultSetExtractor<Role> extractor = new ResultSetExtractor<Role>() {
			public Role extractData(ResultSet rs) throws SQLException, DataAccessException {
				Role model = new Role();
				model.setRoleId(rs.getInt("ROLID"));
				model.setRoleName(rs.getString("ROLNME"));
				model.setRoleDesc(rs.getString("ROLDESC"));
				model.setCreateUser(rs.getString("CREBY"));
				model.setCreateDate(rs.getDate("CREDAT"));
				model.setUpdateUser(rs.getString("UPDBY"));
				model.setUpdateDate(rs.getDate("UPDDAT"));
				model.setActive(rs.getString("ACTIVE"));
				model.setUserGrant(rs.getString("USER_GRANT"));
				model.setRoomGrant(rs.getString("ROOM_GRANT"));
				model.setResidentGrant(rs.getString("RESIDENT_GRANT"));
				return model;
			}
		};
		return extractor.extractData(rs);
	}
}